import requests
# import parsel
from lxml import etree

for page in range(1, 20):
    print(f'==========================正在下载第{page}页======================')
    url = f'https://sc.chinaz.com/tupian/renwutupian_{page}.html'
    resp = requests.get(url)
    # print(resp)
    # selector = parsel.Selector(resp.text)
    # url_list = selector.css('.masonry-brick .bot-div a::attr(href)').getall()

    et = etree.HTML(resp.text)
    url_list = et.xpath('/html/body/div[3]/div[2]/div/div/a/@href')
    # print(len(url_list))
    damo = 'https://sc.chinaz.com'
    damo_1 = 'https:'
    for i in url_list:
        url_1 = damo + i
        resp_1 = requests.get(url=url_1).text
        'https://tppic.chinaz.net/files/default/imgs/2022-10-30/3d916cf13348f951_big.jpg'
        'https://scpic.chinaz.net/files/default/imgs/2022-10-30/3d916cf13348f951_big.jpg'
        'https://scpic.chinaz.net/files/default/imgs/2022-10-30/3d916cf13348f951.jpg'
        et_1 = etree.HTML(resp_1)
        img_url = et_1.xpath('/html/body/div[3]/div[1]/div[1]/div[2]/div[2]/img/@src')
        imgs_url = damo_1 + img_url[0]
        # print(imgs_url.replace('.jpg', '_big.jpg'))

        name = imgs_url.split('/')[-1]
        resp_3 = requests.get(imgs_url)
        with open(f'img/{name}', mode='wb')as f:
            f.write(resp_3.content)
        print(f'{name}下载完成！！！！')
    print(f'==========================第{page}页下载完成======================')

print('全部下载完成！！！！！！！！！！！！！！！！！！')
